package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.DiagnosisReportDao;
import com.jiantong.work.impl.manager.DiagnosisReportManager;
import com.jiantong.work.model.DiagnosisReport;
import com.jiantong.work.service.DiagnosisReportWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by maowenjie on 2017/3/27.
 */
@Slf4j
@Service
@RpcProvider
public class DiagnosisReportWriteServiceImpl implements DiagnosisReportWriteService{

    private final DiagnosisReportManager diagnosisReportManager;

    private final DiagnosisReportDao diagnosisReportDao;
    @Autowired
    public DiagnosisReportWriteServiceImpl(DiagnosisReportManager diagnosisReportManager,DiagnosisReportDao diagnosisReportDao) {
        this.diagnosisReportManager = diagnosisReportManager;
        this.diagnosisReportDao=diagnosisReportDao;
    }

    @Override
    public Response<Map<String,Object>> create(DiagnosisReport diagnosisReport,Integer toStatus) {
        try {
            return Response.ok(diagnosisReportManager.createDiagnosisReportManager(diagnosisReport,toStatus));
        }catch (Exception e){
            log.error("failed to create diagnosisReport error :{}",diagnosisReport,toStatus, Throwables.getStackTraceAsString(e));
            return Response.fail("create.diagnosisReport");
        }
    }

    @Override
    public Response<Map<String,Object>> update(DiagnosisReport diagnosisReport,Integer toStatus) {
        try{
            return Response.ok(diagnosisReportManager.updateDiagnosisReportManager(diagnosisReport,toStatus));
        }catch (Exception e){
            log.error("failed to update diagnosisReport error  :{}",diagnosisReport,toStatus, Throwables.getStackTraceAsString(e));
            return Response.fail("update.diagnosisReport");
        }
    }

    @Override
    public Boolean update(DiagnosisReport diagnosisReport) {
        return diagnosisReportDao.update(diagnosisReport);
    }
}
